//! Configuration module for the attestation service.
//!
//! This module provides access to the service configuration loaded from YAML files
//! using the ConfigSingleton pattern from attestation_common.

use serde::Deserialize;
use attestation_common::ConfigSingleton;

/// Main configuration structure that matches the server_config.yaml file structure.
#[derive(Debug, Deserialize)]
pub struct ServerConfig {
    /// Common configuration settings
    pub attestation_common: Option<AttestationCommon>,
    /// Service-specific configuration settings
    pub attestation_service: AttestationService,
}

/// Common configuration settings
#[derive(Debug, Deserialize)]
pub struct AttestationCommon {
    /// YAML parsing support information
    pub yaml_parse_support: String,
}

/// Service-specific configuration settings
#[derive(Debug, Deserialize)]
pub struct AttestationService {
    /// Attestation verifier configuration
    pub attestation_verifier: AttestationVerifier,
    /// Token management configuration
    pub token_management: TokenManagement,
}

/// Attestation verifier configuration
#[derive(Debug, Deserialize)]
pub struct AttestationVerifier {
    /// URL for retrieving signing keys from vault
    pub vault_get_key_url: String,
}

/// Token management configuration
#[derive(Debug, Deserialize)]
pub struct TokenManagement {
    /// JKU (JWK Set URL) value
    pub jku: String,
    /// Key ID
    pub kid: String,
    /// Token existence time in milliseconds
    pub exist_time: String,
    /// Token issuer
    pub iss: String,
    /// EAT profile identifier
    pub eat_profile: String,
}

/// Global configuration singleton instance
/// 
/// This provides direct access to the configuration singleton for the server.
/// Users should call `CONFIG.initialize(path)` to load the configuration and
/// `CONFIG.get_instance()` to access the loaded configuration.
pub static CONFIG: ConfigSingleton<ServerConfig> = ConfigSingleton::new();